package com.tanhua.backmanage.controller;



import com.tanhua.backmanage.service.CommentService;
import com.tanhua.backmanage.vo.PageResultQs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("/manage")
public class CommentController {


    @Autowired
    private CommentService commentService;


    /**
     * 查询评论列表
     *
     * @param page
     * @param pageSize
     * @param sortProp 排序字段
     * @param sortOrder ascending 升序 descending 降序
     * @param publishId
     * @return
     */
    @GetMapping("/messages/comments")
    public ResponseEntity<PageResultQs> queryAllCommentsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                                           @RequestParam("sortProp") String sortProp,
                                                           @RequestParam("sortOrder") String sortOrder,
                                                           @RequestParam("messageID") String publishId) {
        try {
            PageResultQs pageResultQs = commentService.queryAllCommentsList(page, pageSize, sortProp, sortOrder, publishId);
            return ResponseEntity.ok(pageResultQs);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
